package cn.lijida.weiwei.emailServer.controller;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import cn.lijida.weiwei.emailServer.entity.Email;
import cn.lijida.weiwei.emailServer.service.IMailService;

@RestController
@RequestMapping("/mail")
public class EmailController {
	
	private static final Logger log = LoggerFactory.getLogger(EmailController.class);
	
	@Autowired
	private IMailService mailService;

	@RequestMapping("/send")
	public String send(@RequestParam String email,@RequestParam String subject,@RequestParam String content,@RequestParam String template) {
		try{
			Email mail = new Email(email,subject,content,template);
			
			mailService.send(mail);
			
			return "发送成功";
		}catch(Exception e){
			
			log.error("发送失败", e);
			
			return "发送失败:"+e.getMessage();
		}
        
    }
}
